<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
* 
*/
class login extends CI_Controller
{
	
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('url', 'form'));
		$this->load->model('m_login');
	}

	public function index(){
	     $cek = $this->session->userdata('logged_in');
        if (empty($cek)) {
            $this->load->view("v_login");
        } else {
            header('location:' . site_url('news'));
        }
	}

	public function do_login()
	{
		$cek = $this->session->userdata('logged_in');
        if (empty($cek)) {
            $this->form_validation->set_rules('username', 'Username', 'required');
            $this->form_validation->set_rules('password', 'Password', 'required');

            if ($this->form_validation->run() == FALSE) {
                $this->load->view("v_login");
            } else {
                $u = $this->input->post('username');
                $p = $this->input->post('password');
                $this->m_login->getLoginData($u, $p);
            }
        } else {
            redirect('login');
        }
	}

	
    function logout() {
        $this->session->sess_destroy();
        header('location:' . site_url(''));
    }
}

?>